<template>
  <div class="admin-panel">
    <div class="admin-header">
      <h1>管理员控制面板</h1>
      <div class="admin-actions">
        <el-button type="primary" @click="$router.push({ name: 'QueueManagement' })">
          队列管理
        </el-button>
        <el-button type="info" @click="$router.push({ name: 'Debug' })">
          调试工具
        </el-button>
        <el-button type="warning" @click="handleLogout">
          退出管理
        </el-button>
      </div>
    </div>
    
    <div class="admin-content">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-card class="admin-card">
            <template #header>
              <div class="card-header">
                <span>队列管理</span>
                <el-button type="primary" @click="$router.push({ name: 'QueueManagement' })">
                  进入
                </el-button>
              </div>
            </template>
            <div class="card-content">
              <p>管理用户队列，查看待确认和已确认用户，执行队列操作。</p>
              <ul>
                <li>查看队列状态</li>
                <li>管理待确认用户</li>
                <li>查看已确认用户</li>
                <li>清理过期请求</li>
              </ul>
            </div>
          </el-card>
        </el-col>
        
        <el-col :span="12">
          <el-card class="admin-card">
            <template #header>
              <div class="card-header">
                <span>调试工具</span>
                <el-button type="info" @click="$router.push({ name: 'Debug' })">
                  进入
                </el-button>
              </div>
            </template>
            <div class="card-content">
              <p>API调试和系统监控工具，用于测试和诊断系统状态。</p>
              <ul>
                <li>API接口测试</li>
                <li>系统状态检查</li>
                <li>错误日志查看</li>
                <li>性能监控</li>
              </ul>
            </div>
          </el-card>
        </el-col>
      </el-row>
      
      <el-card class="admin-card system-info">
        <template #header>
          <span>系统信息</span>
        </template>
        <div class="system-info-content">
          <el-row :gutter="20">
            <el-col :span="8">
              <div class="info-item">
                <h4>当前时间</h4>
                <p>{{ currentTime }}</p>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="info-item">
                <h4>管理员状态</h4>
                <el-tag type="success">已登录</el-tag>
              </div>
            </el-col>
            <el-col :span="8">
              <div class="info-item">
                <h4>访问路径</h4>
                <code>/admin0230</code>
              </div>
            </el-col>
          </el-row>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
import { ref, onMounted, onUnmounted } from 'vue'
import { useRouter } from 'vue-router'
import { adminLogout, checkAdminAuth } from '../utils/auth'

export default {
  name: 'AdminPanel',
  setup() {
    const router = useRouter()
    const currentTime = ref('')
    let timeInterval = null
    
    const updateTime = () => {
      currentTime.value = new Date().toLocaleString('zh-CN', {
        year: 'numeric',
        month: '2-digit',
        day: '2-digit',
        hour: '2-digit',
        minute: '2-digit',
        second: '2-digit'
      })
    }
    
    const handleLogout = () => {
      adminLogout()
      router.push({ name: 'Home' })
    }
    
    onMounted(() => {
      // 检查管理员认证状态
      if (!checkAdminAuth()) {
        router.push({ name: 'AdminLogin' })
        return
      }
      
      // 更新时间
      updateTime()
      timeInterval = setInterval(updateTime, 1000)
    })
    
    onUnmounted(() => {
      if (timeInterval) {
        clearInterval(timeInterval)
      }
    })
    
    return {
      currentTime,
      handleLogout
    }
  }
}
</script>

<style scoped>
.admin-panel {
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 15px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.admin-header h1 {
  color: #333;
  margin: 0;
  font-size: 28px;
  font-weight: bold;
}

.admin-actions {
  display: flex;
  gap: 10px;
}

.admin-content {
  margin-top: 20px;
}

.admin-card {
  margin-bottom: 20px;
  border-radius: 15px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: bold;
  font-size: 16px;
}

.card-content {
  padding: 10px 0;
}

.card-content p {
  color: #666;
  margin-bottom: 15px;
  line-height: 1.6;
}

.card-content ul {
  margin: 0;
  padding-left: 20px;
}

.card-content li {
  color: #666;
  margin-bottom: 5px;
  line-height: 1.5;
}

.system-info {
  margin-top: 20px;
}

.system-info-content {
  padding: 10px 0;
}

.info-item {
  text-align: center;
  padding: 15px;
}

.info-item h4 {
  color: #333;
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: bold;
}

.info-item p {
  color: #666;
  margin: 0;
  font-size: 16px;
}

.info-item code {
  background: #f5f5f5;
  padding: 5px 10px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 14px;
  color: #333;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .admin-header {
    flex-direction: column;
    gap: 20px;
    text-align: center;
  }
  
  .admin-actions {
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .admin-panel {
    padding: 10px;
  }
}
</style>
